<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>材质_雷达扫描</title>
    <link href="../Build/Cesium/Widgets/widgets.css" rel="stylesheet" />
    <script src="../Build/Cesium/Cesium.js"></script>
    <style>
        html,
        body,
        #cesiumContainer {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }

        #canvas-a {
            top: 10px;
            display: none;
        }

        #canvas-b {
            top: 120px;
            display: none;
        }
    </style>

</head>

<body>
    <div id="cesiumContainer"></div>
    <canvas id="canvas-a" class="canvas" width="300" height="300"></canvas>
    <script>
        let osm = Cesium.createOpenStreetMapImageryProvider({
            url: 'https://a.tile.openstreetmap.org/'
        });
        let viewer = new Cesium.Viewer('cesiumContainer', {
            imageryProvider: osm,
            contextOptions: {
                webgl: {
                    alpha: true
                }
            },
            selectionIndicator: false,
            animation: false,  //是否显示动画控件
            baseLayerPicker: false, //是否显示图层选择控件
            geocoder: false, //是否显示地名查找控件
            timeline: false, //是否显示时间线控件
            sceneModePicker: false, //是否显示投影方式控件
            navigationHelpButton: false, //是否显示帮助信息控件
            infoBox: false,  //是否显示点击要素之后显示的信息
            fullscreenButton: false
        });
        //取消双击事件
        viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
        //设置homebutton的位置
        Cesium.Camera.DEFAULT_VIEW_RECTANGLE =
            Cesium.Rectangle.fromDegrees(110.15, 34.54, 110.25, 34.56);//Rectangle(west, south, east, north)
        //设置初始位置
        viewer.camera.setView({
            destination: Cesium.Cartesian3.fromDegrees(110.20, 34.55, 3000000)
        });

        //开启深度检测
        viewer.scene.globe.depthTestAgainstTerrain = true;

        let rotation = Cesium.Math.toRadians(30);

        function getRotationValue() {
            rotation -= 0.02;
            return rotation;
        }

        function drawCanvas() {
            let canvas = document.getElementById("canvas-a");
            let context = canvas.getContext('2d');
			let grd = context.createLinearGradient(175, 100, canvas.width, 150);
			grd.addColorStop(0, "rgba(0,255,0,0)");
			grd.addColorStop(1, "rgba(0,255,0,1)");
			context.fillStyle = grd;
			context.beginPath();
			context.moveTo(150, 150);
			context.arc(150, 150, 140, -90 / 180 * Math.PI, 0 / 180 * Math.PI);//context.arc(x,y,r,sAngle,eAngle,counterclockwise);
			context.fill();
            return canvas;
        }

        let i=0;
        viewer.entities.add({
            name: 'Rotating rectangle with rotating texture coordinate',
            rectangle: {
                coordinates: new Cesium.CallbackProperty(function(){
                    return Cesium.Rectangle.fromDegrees(-75.0, 30.0, -70.0, 35.0)
                },false),
                material: new Cesium.ImageMaterialProperty({
                    image: new Cesium.CallbackProperty(drawCanvas, false),
                    transparent: true
                }),
                rotation: new Cesium.CallbackProperty(getRotationValue, false),
                stRotation: new Cesium.CallbackProperty(getRotationValue, false)
            }
        });

        viewer.zoomTo(viewer.entities);

    </script>
</body>

</html>